<template>
	<view style="position: relative;">
		<!-- 公告 ——start -->
		<view class="marquee-root" v-if="contentIsShow">
			<view class="marquee-content">
				<view class="content">
					<view class="iconfont icon-gonggao" style="color: #EEC900;"></view>
					<view class="text">
						{{content}}
					</view>
				</view>
			</view>
		</view>
		<!-- 公告 ——end -->
		<view class="head">
			<!-- <u-icon name="plus" color="#000000" size="50" style="margin-left: 10rpx;" @click="showSaveCourse = true"></u-icon> -->
			<view class="left">
				<text class="iconfont icon-shuaxin" style="font-size: 40rpx;font-weight: 700; color: #5C5C5C;"
					@click="upDate()"></text>
			</view>
			<view class="checkWeek">
				<img src="http://1.14.247.152:9797/images/19693n2.png" class="zuoCss" v-show="selectWeek > 1 "
					@tap="weekCut"></img>
				<picker @change="confirmWeek" :value="0" :range="list">
					<button class="title">
						<view class="showWeek">第{{selectWeek}}周</view>
						<view class="weekText" v-if="currentWeek == selectWeek">(本周)</view>
					</button>
				</picker>
				<img src="http://1.14.247.152:9797/images/11940n.png" @tap="weekPut" v-if="selectWeek < 20 "
					class="youCss"></img>

				<!-- 占位置，防止偏移 -->
				<view v-if="selectWeek >= 20" class="youCss">
				</view>
			</view>
			<!-- class="iconfont2 icon-fanhui2" -->
			<view class="right">
				<!-- <text class="iconfont icon-pingjiao" style="font-size: 45rpx;" @click="toEvaluate()"></text> -->
				<view class="iconfont icon-tianjia" style="font-size: 45rpx;font-weight: 700; margin-left: 50rpx;"
					@tap="showSaveCourse = true">

				</view>
			</view>
		</view>
		<Timetable @getCourseNewData="getCourseNewData()" :timetables="timetables" :timetableType="timetableType"
			:xingqiColor="xingqiColor" :currentWeek="currentWeek" :selectWeek="selectWeek"
			@getCourseData="getCourseData" :canDelete="true">
		</Timetable>


		<!-- 添加课程表单 -->
		<view>
			<u-modal v-model="showSaveCourse" title="添加课程" :zoom=false :show-cancel-button=true @confirm="confirmSubmit"
				@cancel="cancelSave">
				<view class="ui-all">
					<view class="ui-list commom">
						<text style="font-weight: bold;">课程名</text>
						<input type="text" placeholder="请输入课程名" v-model="addCourseForm.courseName"
							placeholder-class="place" />
					</view>
					<!-- 							<view class="ui-list commom">
								<text>教师</text>
								<input type="text" placeholder="请输入教师" v-model="addCourseForm.teacher"
									placeholder-class="place" />
							</view> -->
					<view class="ui-list commom">
						<text>教室</text>
						<input type="text" placeholder="请输入教室" v-model="addCourseForm.local"
							placeholder-class="place" />
					</view>
					<view class=" commom">
						<view>
							<text style="font-weight: bold;">星期</text>
							<picker @change="confirmXingqi" :value="0" :range="xingqiSelect">
								<text class="addSectionText">{{selectXingqiText}}</text>
							</picker>

							<!-- <u-icon name="close-circle-fill" size="30" class="clearIcon" @click="addSectionText = ''"></u-icon> -->
							<u-icon name="arrow-down" color="#000000" size="50" class="sectionIcon"
								@click="saveXingqiSelect = true"></u-icon>
						</view>
					</view>
					<view class="commom">
						<view>
							<text style="font-weight: bold;">节次</text>
							<picker @change="confirmSection" :value="0" :range="sectionsList">
								<!-- <text class="addSectionText" @click="saveCourseSelect = true">{{selectSectionText}}</text> -->
								<text class="addSectionText">{{selectSectionText}}</text>
							</picker>
							<u-icon name="close-circle-fill" size="30" color="#8E8E8E" class="clearIcon"
								@click="clearSelectText">
							</u-icon>
							<!-- <u-icon name="close-circle-fill" size="30" class="clearIcon" @click="addSectionText = ''"></u-icon> -->
							<u-icon name="arrow-down" color="#000000" size="50" class="sectionIcon"
								@click="saveCourseSelect = true"></u-icon>

						</view>
					</view>


					<view class="commom">
						<view>
							<text style="font-weight: bold;">周次</text>
							<picker @change="confirmWeekSelects" :value="0" :range="list">
								<text class="addWeeksText place">{{selectWeeksText}}</text>
							</picker>

							<u-icon name="close-circle-fill" size="30" color="#8E8E8E" class="clearIcon"
								@click="clearWeekText">
							</u-icon>
							<u-icon name="arrow-down" color="#000000" size="50" class="sectionIcon"
								@click="saveCourseWeek = true"></u-icon>
						</view>
					</view>
				</view>
			</u-modal>
		</view>
		<!-- 		<view class="ticketTip" :style="'bottom:16'  + 'px;left:' + (screenWidth/4.5) + 'px;'">
			<text class="iconfont icon-gonggao" style="color: #EEC900;"></text>
			<text>【淘宝官方优惠券】</text>
			<text class="critle" :style="'left:' + (screenWidth/8) + 'px;'"></text>
		</view> -->
		<tickTip @closeTicket="closeTicket()" v-if="showTickTip"></tickTip>
		<!-- <u-tabbar v-model="current" :list="tabbarList" :mid-button="true"></u-tabbar> -->
	</view>
</template>

<script>
	import Timetable from '@/components/lpx-timetable/lpx-timetable';
	import tickTip from '@/components/tickTip/tickTip.vue'

	export default {
		data() {
			return {
				showTickTip: false, //展示提示框
				screenWidth: 0, //屏幕宽度
				statusBarHeight: 0,
				timetableType: [],
				timetables: [],
				// week: ['一', '二', '三', '四', '五', '六', '日'],
				loadPa: 0, //定时器确认是否爬完id
				successPa: false,
				selectWeek: 1,
				currentWeek: 1,
				// currentXingqi: 0,
				showSwitchWeek: false,
				list: ['1', '2', '3', '4', '5',
					'6', '7', '8', '9', '10',
					'11', '12', '13', '14', '15',
					'16', '17', '18', '19', '20'
				],
				sectionsList: [
					'1', '2', '3', '4', '5',
					'6', '7', '8', '9', '10',
					'11', '12'
				],
				show: false,
				xingqiColor: false,
				//添加课表
				addCourseForm: {
					courseName: '',
					// teacher: '',
					local: '',
					section: [],
					dayOfWeek: '',
					weeks: []
				},
				showSaveCourse: false,
				saveCourseSelect: false,
				sectionsSelect: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
				selectSectionText: '(可多选)',
				saveCourseWeek: false,
				weekSelect: [{
						value: '1',
						label: '第1周',
						extra: '1'
					}, {
						value: '2',
						label: '第2周',
						extra: '2'
					}, {
						value: '3',
						label: '第3周',
						extra: '3'
					},
					{
						value: '4',
						label: '第4周',
						extra: '4'
					}, {
						value: '5',
						label: '第5周',
						extra: '5'
					}, {
						value: '6',
						label: '第6周',
						extra: '6'
					},
					{
						value: '7',
						label: '第7周',
						extra: '7'
					}, {
						value: '8',
						label: '第8周',
						extra: '8'
					}, {
						value: '9',
						label: '第9周',
						extra: '9'
					},
					{
						value: '10',
						label: '第10周',
						extra: '10'
					}, {
						value: '11',
						label: '第11周',
						extra: '11'
					}, {
						value: '12',
						label: '第12周',
						extra: '12'
					},
					{
						value: '13',
						label: '第13周',
						extra: '13'
					}, {
						value: '14',
						label: '第14周',
						extra: '14'
					}, {
						value: '15',
						label: '第15周',
						extra: '15'
					},
					{
						value: '16',
						label: '第16周',
						extra: '16'
					}, {
						value: '17',
						label: '第17周',
						extra: '17'
					}, {
						value: '18',
						label: '第18周',
						extra: '18'
					},
					{
						value: '19',
						label: '第19周',
						extra: '19'
					}, {
						value: '20',
						label: '第20周',
						extra: '20'
					}
				],
				selectWeeksText: '(可多选)',
				saveXingqiSelect: false,
				selectXingqiText: '请选择星期',
				// xingqiSelect: [{
				xingqiSelect: ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'],
				weekSelectDefault: [],
				sectionSelectDefault: [],
				xingqiSelectDefault: [],
				courseDataIndex: ['Mon', 'Tue', 'Win', 'Thr', 'Fri', 'Sat', 'Sun'],
				firstIn: true,
				content: '', //横幅内容
				contentIsShow: false,
				tabbarList: []//导航栏list
			}
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '正在加载课表',
				// mask: true
			})
			this.getCourseNewData(this.selectWeek, () => {
				uni.stopPullDownRefresh()
			});

		},
		components: {
			Timetable,
			tickTip
		},
		async onLoad(option) {
			let vm = this
			let app = getApp();
			// console.log('首页')
			// this.loadPage();
			this.statusBarHeight = wx.getSystemInfoSync().statusBarHeight;
			this.screenWidth = wx.getSystemInfoSync().screenWidth;
			setTimeout(() => {
				this.showTickTip = uni.getStorageSync('showTickTip')
				console.log(this.showTickTip )
			},1000)
			// console.log('屏幕宽度',this.screenWidth)
			app.watch('isHaiZhu', () => {
				let temp
				if (getApp().globalData.isHaiZhu == true) {
					temp = [{
							index: '1',
							name: '08:00 08:40'
						},
						{
							index: '2',
							name: '08:50 09:30'
						},
						{
							index: '3',
							name: '09:50 10:30'
						},
						{
							index: '4',
							name: '10:40 11:20'
						},
						{
							index: '5',
							name: ''
						},
						{
							index: '6',
							name: '14:30 15:10'
						},
						{
							index: '7',
							name: '15:20 16:00'
						},
						{
							index: '8',
							name: '16:20 17:00'
						},
						{
							index: '9',
							name: '17:10 17:50'
						},
						{
							index: '10',
							name: '19:30 20:10'
						},
						{
							index: '11',
							name: '20:20 21:00'
						},
						{
							index: '12',
							name: '21:10 21:50'
						}
					]
				} else {
					temp = [{
							index: '1',
							name: '08:40 09:20'
						},
						{
							index: '2',
							name: '09:30 10:10'
						},
						{
							index: '3',
							name: '10:30 11:10'
						},
						{
							index: '4',
							name: '11:20 12:00'
						},
						{
							index: '5',
							name: '     '
						},
						{
							index: '6',
							name: '13:30 14:10'
						},
						{
							index: '7',
							name: '14:20 15:00'
						},
						{
							index: '8',
							name: '15:20 16:00'
						},
						{
							index: '9',
							name: '16:10 16:50'
						},
						{
							index: '10',
							name: '19:00 19:40'
						},
						{
							index: '11',
							name: '19:50 20:30'
						},
						{
							index: '12',
							name: '20:40 21:20'
						}
					]
				}
				vm.timetableType = temp
				// console.log(vm.timetableType)
			})
			app.watch("isPasswordError", (value) => {
				console.log("密码改变了" + value)
				if (value) {
					uni.showModal({
						title: '温馨提示',
						content: '检测到您在教务网修改了密码，为了确保数据准确，请前往更新密码',
						confirmText: '前往',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '../passwordChange/passwordChange'
								})
							} else if (res.cancel) {
								//console.log('用户点击取消');
							}
						}
					});
				}
			})


		},
		async onShow() {
			// uni.showLoading({
			// 	title: '请稍等..',
			// mask: true
			// mask: true
			// })
			this.showTickTip = uni.getStorageSync('showTickTip')
			console.log(this.showTickTip )
			
		
			if (getApp().globalData.firstIn) {
				console.log('第一次登录')
				getApp().watch('firstIn', (value) => {
					if (!value) {
						console.log('加载')
						this.loadPage()
					}
				})
			} else {
				console.log('不是第一次加入')
				this.loadPage();
			}

			this.marquee()
		},
		computed: {
			currentXingqi() {
				let xingqi = "7123456".charAt(new Date().getDay());
				return xingqi
			}
		},
		methods: {
			closeTicket() {
				uni.setStorageSync('showTickTip',false);
				this.showTickTip = false
			},
			//横幅
			async marquee() {
				let header = new Object()
				header.Authority = uni.getStorageSync("Authority")
				let res = await getApp().UniRequest("/notice/getNotice?id=1", "Get", "", header);
				// console.log(res, '横幅');
				if (res.code === 20000) {
					this.content = res.data.data.content;
					// console.log(this.content, '横幅内容');
					if (res.data.data.isShow === 1) {
						this.contentIsShow = res.data.data.isShow
					}

				}
			},
			async loadPage() {
				let vm = this
				let header = new Object()
				header.Authority = uni.getStorageSync("Authority")
				let res = await getApp().UniRequest("/week", "Get", "", header);
				// console.log(res, '周次')
				uni.hideLoading()
				vm.selectWeek = res.data.week;
				vm.currentWeek = res.data.week;

				setTimeout(async function() {
					//默认的当前周

					if (getApp().globalData.newPerson) {
						uni.showModal({
							title: '首次加载课表大概需要120秒',
							confirmText: "确认",
							showCancel: false,
							success: (res) => {
								if (res.confirm) {
									uni.showLoading({
										title: '请稍等..',
										// mask: true
									})
									setTimeout(() => {
										uni.hideLoading();
										vm.awaitPa();
										getApp().globalData.newPerson = false
										// vm.getCourseData()

									}, 150000)
								}
							}
						})

					} else {

						vm.getCourseData()
					}
				}, 300)

			},

			async awaitPa() {
				let vm = this
				// uni.showLoading({
				// 	title: '请稍等..',
				// mask: true
				// })
				this.isUpdateSuccess(1, 1);
			},
			isUpdateSuccess(time, callback) {
				let header = new Object()
				header.Authority = uni.getStorageSync("Authority")
				setTimeout(async () => {
					let res = await getApp().UniRequest("/coursePlus/authority/isSuccess", "Get", "", header);
					console.log('刷新结果', res);
					if (res.code === 20001) {
						uni.hideLoading();
						uni.showToast({
							title: '请稍后重试',
							icon: 'error',
							duration: 2000
						});
					} else {
						if (callback == 1) {
							this.getCourseData()
							uni.hideLoading();
						}
						if (callback == 2) {
							uni.showToast({
								title: '刷新成功',
								icon: 'success',
								duration: 2000
							});
							this.removeStorge()
							this.getCourseData()
						}
						uni.hideLoading();
					}
				}, time)


			},
			//清空缓存
			removeStorge() {
				uni.removeStorageSync('OneNewData');
				uni.removeStorageSync('TwoNewData');
				uni.removeStorageSync('ThreeNewData');
				uni.removeStorageSync('FOurNewData');
				uni.removeStorageSync('FiveNewData');
				uni.removeStorageSync('SixNewData');
				uni.removeStorageSync('SevenNewData');
				uni.removeStorageSync('EightNewData');
				uni.removeStorageSync('NinNewData');
				uni.removeStorageSync('TenNewData');
				uni.removeStorageSync('EleNewData');
				uni.removeStorageSync('TweNewData');
				uni.removeStorageSync('ThreeTenNewData');
				uni.removeStorageSync('FourTeenNewData');
				uni.removeStorageSync('FiveTeenNewData');
				uni.removeStorageSync('SixTeenNewData');
				uni.removeStorageSync('SevenTeenNewData');
				uni.removeStorageSync('EightTeenNewData');
				uni.removeStorageSync('NithTeenNewData');
				uni.removeStorageSync('TweTyNewData');
			},
			upDateRemoveStorge(week) {
				switch (week) {
					case 1: {
						oldData = uni.getStorageSync('OneNewData');
						break;
					}
					case 2: {
						oldData = uni.getStorageSync('TwoNewData');
						break;
					}
					case 3: {
						oldData = uni.getStorageSync('ThreeNewData');
						break;
					}
					case 4: {
						oldData = uni.getStorageSync('FOurNewData');
						break;
					}
					case 5: {
						oldData = uni.getStorageSync('FiveNewData');
						break;
					}
					case 6: {
						oldData = uni.getStorageSync('SixNewData');
						break;
					}
					case 7: {
						oldData = uni.getStorageSync('SevenNewData');
						break;
					}
					case 8: {
						oldData = uni.getStorageSync('EightNewData');
						break;
					}
					case 9: {
						oldData = uni.getStorageSync('NinNewData');
						break;
					}
					case 10: {
						oldData = uni.getStorageSync('TenNewData');
						break;
					}
					case 11: {
						oldData = uni.getStorageSync('EleNewData');
						break;
					}
					case 12: {
						oldData = uni.getStorageSync('TweNewData');
						break;
					}
					case 13: {
						oldData = uni.getStorageSync('ThreeTenNewData');
						break;
					}
					case 14: {
						oldData = uni.getStorageSync('FourTeenNewData');
						break;
					}
					case 15: {
						oldData = uni.getStorageSync('FiveTeenNewData');
						break;
					}
					case 16: {
						oldData = uni.getStorageSync('SixTeenNewData');
						break;
					}
					case 17: {
						oldData = uni.getStorageSync('SevenTeenNewData');
						break;
					}
					case 18: {
						oldData = uni.getStorageSync('EightTeenNewData');
						break;
					}
					case 19: {
						oldData = uni.getStorageSync('NithTeenNewData');
						break;
					}
					case 20: {
						oldData = uni.getStorageSync('TweTyNewData');
						break;
					}
				}
			},
			async getCourseData(callback) {
				uni.showLoading({
					title: '正在加载课表',
					// mask: true
				})
				// console.log('重新获取课程表')
				let vm = this
				if (vm.selectWeek == vm.currentWeek) {
					vm.xingqiColor = true
				} else {
					vm.xingqiColor = false
				}
				let header = new Object()
				header.Authority = uni.getStorageSync("Authority")

				let body = new Object();
				body.week = vm.selectWeek;

				let currentTime = Date.parse(new Date());
				// console.log('当前时间', undefined < currentTime)
				//没有缓存过期时间或者当前时间大于过期时间了

				if (!this.getStorage(body.week) || (this.getStorage(body.week).expirationValue < currentTime)) {
					this.getCourseNewData(body.week)
					// console.log('没有缓存过期时间或者当前时间大于过期时间了');
					// // console.log(this.getStorage(body.week).data)
					// // console.log('过期时间', this.getStorage(body.week).expirationValue);

					// let res = await getApp().UniRequest("/coursePlus/authority?week=" + body.week, "Get", body,
					// 	header);
					// // console.log(res.data.list,'课表数据')

					// if (res.code === 20000) {
					// 	vm.timetables = res.data.list;
					// 	let newData = {
					// 		expirationValue: '',
					// 		data: []
					// 	};
					// 	newData.data = res.data.list
					// 	newData.expirationValue = Date.parse(new Date()) + 1728000000;
					// 	// console.log(newData)
					// 	this.setNewStorge(body.week, newData)
					// 	uni.hideLoading()
					// } else {

					// 	//请求失败，若有缓存，任然用缓存的，因为课表的更新并不大
					// 	if (this.getStorage(body.week)) {
					// 		this.timetables = this.getStorage(body.week).data;
					// 		// console.log('获取缓存数据', this.getStorage(body.week).data)
					// 		uni.hideLoading();
					// 	} else {
					// 		//无缓存
					// 		uni.showToast({
					// 			title: '请稍后重试',
					// 			icon: 'error',
					// 			duration: 2000
					// 		});
					// 	}
					// }

				} else {
					// console.log('有缓存数据')
					this.timetables = this.getStorage(body.week).data;
					console.log(this.timetables)
					// console.log('获取缓存数据', this.getStorage(body.week).data)
					// console.log('过期时间', this.getStorage(body.week).expirationValue)
					uni.hideLoading()
				}

				callback && callback()

			},
			async getCourseNewData(week, callback) {

				let body = new Object();
				body.week = week;
				let header = new Object()
				header.Authority = uni.getStorageSync("Authority");
				let res = await getApp().UniRequest("/coursePlus/authority?week=" + body.week, "Get", body,
					header);
				// console.log(res.data.list, '课表数据')
				// console.log(body.week)
				if (res.code === 20000) {
					// this.timetables = res.data.list;
					let newData = {
						expirationValue: '',
						data: []
					};
					newData.data = res.data.list
					newData.expirationValue = Date.parse(new Date()) + 1728000000;
					// console.log(body.week)
					
					this.setNewStorge(body.week, newData);
					 this.timetables = newData.data || this.getStorage(this.selectWeek).data
					 console.log(newData)
					uni.hideLoading()
				} else {
					// uni.showToast({
					// 	title: '请稍后重试',
					// 	icon: 'error',
					// 	duration: 2000
					// });
				}
				callback && callback()
			},

			//拿取缓存数据
			getStorage(week) {
				let oldData;
				switch (week) {
					case 1: {
						oldData = uni.getStorageSync('OneNewData');
						break;
					}
					case 2: {
						oldData = uni.getStorageSync('TwoNewData');
						break;
					}
					case 3: {
						oldData = uni.getStorageSync('ThreeNewData');
						break;
					}
					case 4: {
						oldData = uni.getStorageSync('FOurNewData');
						break;
					}
					case 5: {
						oldData = uni.getStorageSync('FiveNewData');
						break;
					}
					case 6: {
						oldData = uni.getStorageSync('SixNewData');
						break;
					}
					case 7: {
						oldData = uni.getStorageSync('SevenNewData');
						break;
					}
					case 8: {
						oldData = uni.getStorageSync('EightNewData');
						break;
					}
					case 9: {
						oldData = uni.getStorageSync('NinNewData');
						break;
					}
					case 10: {
						oldData = uni.getStorageSync('TenNewData');
						break;
					}
					case 11: {
						oldData = uni.getStorageSync('EleNewData');
						break;
					}
					case 12: {
						oldData = uni.getStorageSync('TweNewData');
						break;
					}
					case 13: {
						oldData = uni.getStorageSync('ThreeTenNewData');
						break;
					}
					case 14: {
						oldData = uni.getStorageSync('FourTeenNewData');
						break;
					}
					case 15: {
						oldData = uni.getStorageSync('FiveTeenNewData');
						break;
					}
					case 16: {
						oldData = uni.getStorageSync('SixTeenNewData');
						break;
					}
					case 17: {
						oldData = uni.getStorageSync('SevenTeenNewData');
						break;
					}
					case 18: {
						oldData = uni.getStorageSync('EightTeenNewData');
						break;
					}
					case 19: {
						oldData = uni.getStorageSync('NithTeenNewData');
						break;
					}
					case 20: {
						oldData = uni.getStorageSync('TweTyNewData');
						break;
					}
				}
				return oldData;
			},


			//更新缓存数据
			setNewStorge(week, courseData) {
				switch (week) {
					case 1: {
						uni.setStorageSync('OneNewData', courseData);
						break;
					}
					case 2: {
						console.log('执行')
						uni.setStorageSync('TwoNewData', courseData);
						break;
					}
					case 3: {
						uni.setStorageSync('ThreeNewData', courseData);
						break;
					}
					case 4: {
						uni.setStorageSync('FOurNewData', courseData);
						break;
					}
					case 5: {
						uni.setStorageSync('FiveNewData', courseData);
						break;
					}
					case 6: {
						uni.setStorageSync('SixNewData', courseData);
						break;
					}
					case 7: {
						uni.setStorageSync('SevenNewData', courseData);
						break;
					}
					case 8: {
						uni.setStorageSync('EightNewData', courseData);
						break;
					}
					case 9: {
						uni.setStorageSync('NinNewData', courseData);
						break;
					}
					case 10: {
						uni.setStorageSync('TenNewData', courseData);
						break;
					}
					case 11: {
						uni.setStorageSync('EleNewData', courseData);
						break;
					}
					case 12: {
						uni.setStorageSync('TweNewData', courseData);
						break;
					}
					case 13: {
						uni.setStorageSync('ThreeTenNewData', courseData);
						break;
					}
					case 14: {
						uni.setStorageSync('FourTeenNewData', courseData);
						break;
					}
					case 15: {
						uni.setStorageSync('FiveTeenNewData', courseData);
						break;
					}
					case 16: {
						uni.setStorageSync('SixTeenNewData', courseData);
						break;
					}
					case 17: {
						uni.setStorageSync('SevenTeenNewData', courseData);
						break;
					}
					case 18: {
						uni.setStorageSync('EightTeenNewData', courseData);
						break;
					}
					case 19: {
						uni.setStorageSync('NithTeenNewData', courseData);
						break;
					}
					case 20: {
						uni.setStorageSync('TweTyNewData', courseData);
						break;
					}
				}
			},

			async weekPut() {
				this.selectWeek++;
				this.getCourseData()
			},
			async weekCut() {
				this.selectWeek--;
				this.getCourseData()
			},
			cancelSave() {
				this.addCourseForm = {
					courseName: '',
					// teacher: '',
					local: '',
					dayOfWeek: '',
					section: [],
					weeks: []
				}
				this.selectSectionText = '（可多选）',
					this.selectWeeksText = '(可多选)',
					this.selectXingqiText = '请选择星期'
				this.weekSelectDefault[0] = '0'
				this.sectionSelectDefault[0] = '0'
				this.xingqiSelectDefault[0] = '0'
			},
			confirmWeek(res) {
				this.selectWeek = parseInt(res.detail.value) + 1
				this.getCourseData()
			},
			// confirmSection(res) {
			// 	let value = res.detail.value
			// 	if (value == '0') {
			// 		this.addCourseForm.section = '0,1'
			// 		this.selectSectionText = '1-2节'
			// 		this.sectionSelectDefault[0] = 0
			// 	} else if (value == '1') {
			// 		this.addCourseForm.section = '2,3'
			// 		this.selectSectionText = '3-4节'
			// 		this.sectionSelectDefault[0] = 1
			// 	} else if (value == '2') {
			// 		this.addCourseForm.section = '4'
			// 		this.selectSectionText = '第5节'
			// 		this.sectionSelectDefault[0] = 2
			// 	} else if (value == '3') {
			// 		this.addCourseForm.section = '6,7'
			// 		this.selectSectionText = '6-7节'
			// 		this.sectionSelectDefault[0] = 3
			// 	} else if (value == '4') {
			// 		this.addCourseForm.section = '8,9'
			// 		this.selectSectionText = '8-9节'
			// 		this.sectionSelectDefault[0] = 4
			// 	} else {
			// 		this.addCourseForm.section = '10,11,12'
			// 		this.selectSectionText = '10-12节'
			// 		this.sectionSelectDefault[0] = 5
			// 	}
			// },
			confirmSection(res) {
				if (this.addCourseForm.section.indexOf(parseInt(res.detail.value)) == -1) {
					this.addCourseForm.section.push(parseInt(res.detail.value))
					if (this.selectSectionText == '(可多选)') {
						this.selectSectionText = (parseInt(res.detail.value) + 1)
					} else {
						this.selectSectionText += (',' + (parseInt(res.detail.value) + 1))
					}
				}
				this.sectionSelectDefault[0] = res.detail.value
			},
			clearSelectText() {
				this.selectSectionText = '(可多选)',
					this.addCourseForm.section = []
			},
			confirmWeekSelects(res) {
				if (this.addCourseForm.weeks.indexOf(parseInt(res.detail.value) + 1) == -1) {
					this.addCourseForm.weeks.push(parseInt(res.detail.value) + 1)
					if (this.selectWeeksText == '(可多选)') {
						this.selectWeeksText = (parseInt(res.detail.value) + 1)
					} else {
						this.selectWeeksText += (',' + (parseInt(res.detail.value) + 1))
					}
				}
				this.weekSelectDefault[0] = res.detail.value
			},
			clearWeekText() {
				this.selectWeeksText = '(可多选)',
					this.addCourseForm.weeks = []
			},
			confirmXingqi(res) {
				if (res.detail.value == '0') {
					this.addCourseForm.dayOfWeek = 0
					this.selectXingqiText = '星期一',
						this.xingqiSelectDefault[0] = 0
				} else if (res.detail.value == '1') {
					this.addCourseForm.dayOfWeek = 1
					this.selectXingqiText = '星期二',
						this.xingqiSelectDefault[0] = 1
				} else if (res.detail.value == '2') {
					this.addCourseForm.dayOfWeek = 2
					this.selectXingqiText = '星期三',
						this.xingqiSelectDefault[0] = 2
				} else if (res.detail.value == '3') {
					this.addCourseForm.dayOfWeek = 3
					this.selectXingqiText = '星期四',
						this.xingqiSelectDefault[0] = 3
				} else if (res.detail.value == '4') {
					this.addCourseForm.dayOfWeek = 4
					this.selectXingqiText = '星期五',
						this.xingqiSelectDefault[0] = 4
				} else if (res.detail.value == '5') {
					this.addCourseForm.dayOfWeek = 5
					this.selectXingqiText = '星期六',
						this.xingqiSelectDefault[0] = 5
				} else {
					this.addCourseForm.dayOfWeek = 6
					this.selectXingqiText = '星期日',
						this.xingqiSelectDefault[0] = 6
				}

			},
			cancelWeekSelection(res) {
				this.weekSelectDefault[0] = res[0].value - 1
			},
			cancelSectionSelection(res) {
				// console.log(res)
				this.sectionSelectDefault[0] = res[0].extra - 1
			},
			cancelXingqiSelection(res) {
				this.xingqiSelectDefault[0] = res[0].value - 1
			},
			async confirmSubmit() {
				let vm = this
				//验证表单信息是否完整
				if (vm.addCourseForm.courseName == '') {
					uni.showToast({
						title: '请输入课程名！',
						icon: 'error'
					})
					vm.showSaveCourse = true
				} else if (vm.selectXingqiText == '请选择星期') {
					uni.showToast({
						title: '请选择星期！',
						icon: 'error'
					})
					vm.showSaveCourse = true
				} else if (vm.selectSectionText == '(可多选)') {
					uni.showToast({
						title: '请选择节次！',
						icon: 'error'
					})
					vm.showSaveCourse = true

				} else if (vm.addCourseForm.weeks.length == 0) {
					uni.showToast({
						title: '请选择周次',
						icon: 'error'
					})
					vm.showSaveCourse = true
				} else {
					//调用接口添加课程
					let header = new Object()
					header.Authority = uni.getStorageSync("Authority")
					let body = new Object()

					body.courseName = vm.addCourseForm.courseName
					// body.teacherName = vm.addCourseForm.teacher
					body.local = vm.addCourseForm.local
					body.section = vm.addCourseForm.section.toString()
					body.weeks = vm.addCourseForm.weeks
					body.dayOfWeek = parseInt(vm.addCourseForm.dayOfWeek) + 1
					console.log(body, '加课参数')
					let res = await getApp().UniRequest("/coursePlus/authority", "POST", body, header);
					console.log(res.data);
					if (res.code == 20000) {
						uni.showToast({
							title: '添加成功！'
						})
						setTimeout(function() {
							uni.showLoading({
								title: '正在加载课表',
								// mask: true
							})

							body.weeks.forEach((item, index) => {
								console.log(item)
								vm.getCourseNewData(item);
								if (index != body.weeks.length - 1) {
									uni.showLoading({
										title: '正在加载课表',
										// mask: true
									})
								}
							})
						}, 1000)

					} else if (res.code == 20001) {
						uni.showToast({
							title: '课程有冲突哦！',
						})
					}
					//添加之后清零
					this.addCourseForm = {
						courseName: '',
						// teacher: '',
						local: '',
						dayOfWeek: '',
						section: [],
						weeks: []
					}
					this.selectSectionText = '(可多选)',
						this.selectWeeksText = '(可多选)',
						this.selectXingqiText = '请选择星期'
					this.weekSelectDefault[0] = '0'
					this.sectionSelectDefault[0] = '0'
					this.xingqiSelectDefault[0] = '0'
				}
			},
			upDate() {
				let vm = this
				let header = new Object()
				header.Authority = uni.getStorageSync("Authority")
				uni.showModal({
					title: '确定重新导入课表吗？这可能需要120秒，且您添加的课程将丢失。',
					confirmText: '确定',
					cancelText: '取消',
					async success(i) {
						if (i.confirm) {
							getApp().globalData.successPa == false
							uni.showLoading({
								title: '刷新中...',
								mask: true
							});
							console.log('执行1111')
							let res = await getApp().UniRequest("/coursePlus/authority", "PUT", "", header);
							console.log(res, '刷新结果')
							if (res.code == 20000) {
								vm.isUpdateSuccess(150000, 2)
							} else {
								uni.showToast({
									title: '请稍后重试',
									icon: 'error',
									duration: 2000
								});
							}
						}
					}
				})
			},

		}
	}
</script>
<style lang="less" scoped>
	// @import (less) '@/static/lx-calendar/fonts/iconfont.css';

	@color: #86f0be;
	@color_disabled: #f1f1f1;
	@color_standard: #333;
	@color_border: #f5f5f5;

	@keyframes marqueeAnim {
		0% {
			transform: translateX(100vw);
		}

		100% {
			transform: translateX(-100%);
		}
	}

	.ticketTip {
		padding: 20rpx;
		border-radius: 10rpx;
		background: rgba(0, 0, 0, 0.4);
		position: fixed;
		font-size: 26rpx;
		color: #fff;
		text-align: center;

		// margin-bottom: 25rpx;
		.critle {
			position: absolute;
			border: 20rpx solid rgba(0, 0, 0, 0.4);
			border-right: 20rpx solid transparent;
			border-left: 20rpx solid transparent;
			border-bottom: 20rpx solid transparent;
			top: 74rpx;
			// left: 40rpx;
		}

	}


	.marquee-root {
		width: 100%;
		height: 30px;
		text-align: left;
		line-height: 70rpx;
		overflow: hidden;
		background-color: #f5f7fa;

		// background-color: burlywood;
		.marquee-content {
			white-space: nowrap;
			display: inline-block;
			color: #000000;

			font-size: 30rpx;
			animation: marqueeAnim 12s linear 0s infinite;

			.content {
				display: flex;

				.text {
					letter-spacing: 2rpx;
					background-color: #f5f7fa;
				}
			}
		}
	}

	.head {
		display: flex;
		align-items: center;
		height: 100rpx;
		justify-content: center;
		position: relative;
		border-bottom: 1rpx solid @color_border;
		color: @color_standard;
		background-color: #f5f7fa;

		.left {
			position: absolute;
			left: 20rpx;
		}

		.right {
			// margin-right: 20rpx;
			// display: flex;
			position: absolute;
			right: 20rpx;
		}

		.checkWeek {
			width: 300rpx;

			display: flex;
			align-items: center;
			justify-content: center;

			.zuoCss {
				width: 40rpx;
				height: 40rpx;
				text-align: center;
				margin-right: 10rpx;
			}

			.youCss {
				width: 40rpx;
				height: 40rpx;
				margin-left: 10rpx;
			}

			.title {
				font-size: 30rpx;
				font-weight: bold;
				display: flex;
				justify-content: center;
				align-items: center;

				.showWeek {}

				.weekText {
					font-size: 23rpx;
				}
			}
		}


	}

	.ui-all {
		padding: 20rpx 40rpx;

		.avatar {
			width: 100%;
			text-align: left;
			padding: 20rpx 0;
			border-bottom: solid 1px #f2f2f2;
			position: relative;

			.imgAvatar {
				width: 140rpx;
				height: 140rpx;
				border-radius: 50%;
				display: inline-block;
				vertical-align: middle;
				overflow: hidden;

				.iavatar {
					width: 100%;
					height: 100%;
					display: block;
				}
			}

			text {
				display: inline-block;
				vertical-align: middle;
				color: #8e8e93;
				font-size: 28rpx;
				margin-left: 40rpx;
			}

			&:after {
				content: ' ';
				width: 20rpx;
				height: 20rpx;
				border-top: solid 1px #030303;
				border-right: solid 1px #030303;
				transform: rotate(45deg);
				-ms-transform: rotate(45deg);
				/* IE 9 */
				-moz-transform: rotate(45deg);
				/* Firefox */
				-webkit-transform: rotate(45deg);
				/* Safari 和 Chrome */
				-o-transform: rotate(45deg);
				position: absolute;
				top: 85rpx;
				right: 0;
			}
		}

		.commom {
			width: 100%;
			text-align: left;
			padding: 20rpx 0;
			border-bottom: solid 1px #f2f2f2;
			position: relative;
			display: flex;
			margin-left: 25rpx;

			text {
				color: #4a4a4a;
				font-size: 28rpx;
				display: inline-block;
				vertical-align: middle;
				min-width: 150rpx;
			}

			input {
				color: #030303;
				font-size: 26rpx;
				display: inline-block;
				vertical-align: middle;
			}

			button {
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
				background: none;
				margin: 0;
				padding: 0;

				&::after {
					display: none;
				}
			}

			picker {
				width: 90%;
				color: #030303;
				font-size: 30rpx;
				display: inline-block;
				vertical-align: middle;
				position: absolute;
				top: 30rpx;
				left: 150rpx;
			}

			textarea {
				color: #030303;
				font-size: 30rpx;
				vertical-align: middle;
				height: 150rpx;
				width: 100%;
				margin-top: 50rpx;
			}

			.place {
				color: #999999;
				font-size: 26rpx;
			}

			.addSectionText {
				position: absolute;
				font-size: 26rpx;
				color: #999999;
			}

			.clearIcon {
				position: absolute;
				right: 50rpx;
				top: 30rpx;
				max-width: 30rpx;
				// font-size: 	#A1A1A1 ;
			}

			.sectionIcon {
				position: absolute;
				// float: flex;
				// position: relative;
				right: -120rpx
			}



			.addWeeksText {
				// position: absolute;
				max-width: 2000rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				width: 280rpx;
				direction: rtl;
				text-align: left;
				letter-spacing: 3rpx
			}
		}

		.ui-list {
			display: flex;
			align-items: center;
			// justify-content: center;
		}

		.right:after {
			content: ' ';
			width: 20rpx;
			height: 20rpx;
			border-top: solid 1px #030303;
			border-right: solid 1px #030303;
			transform: rotate(45deg);
			-ms-transform: rotate(45deg);
			/* IE 9 */
			-moz-transform: rotate(45deg);
			/* Firefox */
			-webkit-transform: rotate(45deg);
			/* Safari 和 Chrome */
			-o-transform: rotate(45deg);
			position: absolute;
			top: 40rpx;
			right: 0;
		}

		.save {
			background: #030303;
			border: none;
			color: #ffffff;
			margin-top: 40rpx;
			font-size: 28rpx;
		}
	}

	.courseNameBox {
		position: relative;
		// margin: auto;
		border-bottom: solid 1px #f2f2f2;
		text-align: center;

		.courseName {
			position: relative;
			color: #000000;
			font-size: 30rpx;
			font-weight: bold;
		}
	}
</style>
